new Vue({
  el: '#app',
  data() {
    return {
      rules:{
        Article_SerialNumber:[{ required: true, message: '请选择商品', trigger: 'change' }],
        Dealer_Article_SerialNumber:[{ required: true, message: '请选择第三方商品', trigger: 'change' }],
        Tax_Number:[{ required: true, message: '请选择经销商', trigger: 'change' }]
      },
      pickerOptions: pickerOptions,
      form: {
        Dealer_Article_Config_SerialNumber: "",
        Article_SerialNumber: '',
        Dealer_Article_SerialNumber: '',
        Tax_Number: '',
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
      },
      loading: false,
      article:[],
      dealer:[]
    }
  },
  mounted() {
    let Dealer_Article_Config_SerialNumber = sessionStorage.getItem("Dealer_Article_Config_SerialNumber")
    this.getData(Dealer_Article_Config_SerialNumber);
  },
  methods: {
    getData(Primary_Key) {
      let _this = this;
      $.ajax({
        type: 'POST',
        url: DomainName + "/getInquiryAction?token=" + $.cookie('token'),
        data: {
          Data: "article_info",
        },
        success: function (res) {
          _this.article = res;
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
      $.ajax({
        type: 'POST',
        url: DomainName + "/getInquiryAction?token=" + $.cookie('token'),
        data: {
          Data: "dealer_info",
        },
        success: function (res) {
          _this.dealer = res;
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
      $.ajax({
        type: 'POST',
        url: DomainName + "/getInquiryIDOriginal?token=" + $.cookie('token'),
        data: {
          Data: "dealer_article_config",
          Primary_Key,
          Primary_Key_Name:'Dealer_Article_Config_SerialNumber'
        },
        success: function (res) {
          console.log(res);
          _this.form = res[0];
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.loading = true
          $.ajax({
            url: DomainName + '/getEditAction?token=' + $.cookie('token'),
            type: 'POST',
            data: {
              Data: JSON.stringify({
                Modify: {  dealer_article_config: [_this.form] },
              })
            },
            success: function (res) {
              console.log('提交结果', res)
              _this.$message.success("提交成功")
              window.history.go(-1);
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = absolutepath() + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  }
})